package com.pickgliss.toplevel
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.getQualifiedClassName;

	public final class StageReferance
	{
		public static var stageHeight:int
		public static var stageWidth:int
		private static var _stage:Stage;
		/**
		 * 
		 * @param $stage 舞台对象
		 * 初始化 舞台引用
		 * 
		 */		
		public static function setup($stage:Stage):void
		{
			if(_stage != null)return;
			_stage = $stage;
			_stage.addEventListener(Event.EXIT_FRAME,__onNextFrame);
			_stage.addEventListener(Event.RESIZE,__onResize);
			_stage.stageFocusRect = false;
			
//			_stage.addEventListener(Event.ENTER_FRAME, __traceFocus);
		}
		
//		private static var _focus:String;
//		private static function __traceFocus(e:Event):void{
//			var str:String = getQualifiedClassName(_stage.focus);
//			if(_focus != str){
//				_focus = str;
//				trace("=====================>" + _focus);
//			}
//		}
		
		private static function __onNextFrame(event:Event):void
		{
			if(_stage.stageWidth > 0)
			{
				_stage.removeEventListener(Event.EXIT_FRAME,__onNextFrame);
				stageWidth = _stage.stageWidth;
				stageHeight = _stage.stageHeight;
			}
		}
		
		private static function __onResize(event:Event):void
		{
			stageWidth = _stage.stageWidth;
			stageHeight = _stage.stageHeight;
		}
		/**
		 * 
		 * @return 获取舞台
		 * 
		 */		
		public static function get stage():Stage
		{
			return _stage;
		}

		public function StageReferance()
		{
		}
	}
}